package cn.map;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 

public class GetPoint {
	   private static Connection con;
	   private static Statement sql;
	   private static ResultSet res;
	   
	   
	   Connection getConnection(){
	         try {
	            Class.forName("com.mysql.jdbc.Driver");
	            System.out.println("数据库驱动加载成功！");
	        }catch (ClassNotFoundException e){
	            e.printStackTrace();
	        }
	         try {
//	            con = DriverManager.getConnection("jdbc:mysql:"+"//10.129.50.191:3306/yuwenli","root","lkl124268");
	            con = DriverManager.getConnection("jdbc:mysql:"+"//10.129.22.113:3306/dbsheep","root","root");
	            System.out.println("数据库连接成功！");
	        }catch (SQLException e){
	            e.printStackTrace();
	        }
	        return con;
	    }
	     
	public List getpoint(String deviceid,String time) {

		GetPoint ts = new GetPoint();
        ts.getConnection();
        List lists = new ArrayList();
        try {
            sql = con.createStatement();
            res = sql.executeQuery("select * from demopoint_traj where   date(acquisition_time)='"+time+"'and device_num = "+deviceid );
 
            while (res.next()){
                String device_num   =  res.getString("device_num");
                float longitude  =  res.getFloat("LON");
                float latitude  =  res.getFloat("LAT");
 
                System.out.println("  经度：  " + longitude );
                System.out.println("  纬度：  " + latitude );
                
                point point = new point();
          
                point.setlatitude(latitude);        
                point.setlongitude(longitude);
 
                
                lists.add(point);
            }
            return lists;
        }catch (Exception e){
            e.printStackTrace();
        }
    
		return null;
		
	}
	
	 
	
	 
}
